package chpt06;

import java.util.Scanner;

class ArrayUtils {
	public static double findMax(double[] arr, int begin, int end) throws IllegalArgumentException {

		if (begin >= end)
			throw new IllegalArgumentException("begin:" + begin + " >= " + "end:" + end);
		if (begin < 0)
			throw new IllegalArgumentException("begin:" + begin + " < 0");
		if (end > arr.length)
			throw new IllegalArgumentException("end:" + end + " > arr.length");

		double max = arr[begin];
		for (int i = begin; i < end; i++) {
			if (max <= arr[i])
				max = arr[i];
		}
		return max;
	}
}

public class ThrowsAndThrow {

	public static void main(String[] args) throws NumberFormatException {
		Scanner in = new Scanner(System.in);
		double[] arr = new double[in.nextInt()];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = in.nextDouble();
		}
		while (in.hasNext()) {
			try {
				int x=Integer.parseInt(in.next());
				int y=Integer.parseInt(in.next());
				System.out.println(ArrayUtils.findMax(arr, x, y));
			} catch (NumberFormatException e) {
				break;
			} catch (IllegalArgumentException e) {
				System.out.println(e);
			}

		}
		
		try {
			System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class, int.class, int.class));
		} catch (Exception e1) {
		}
		in.close();
	}

}


